home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-02-20 | 4.9 KB | 178 lines | [TEXT/CWIE] |
- /*
- File: Exceptions.c
-
- Contains: exception handling stuff
-
- Written by: Bruce Horn, Steve Capps, Larry Kenyon, John Meier, scott douglass, Darin Adler,
- Paul Mercer, Bryan Stearns, Dave Owens
-
- Andy Nicholas
-
- Copyright: © 1988-1995 by Apple Computer, Inc., all rights reserved.
-
- <2> 2/24/95 ga
- */
-
- #if 0
-
- #ifdef MWTRACEBACKTABLES
- #pragma traceback on
- #endif
-
- #include "Exceptions.h"
- #include "Debug.h"
-
- //
- // For SysError
- //
- #include <Errors.h>
-
- #ifdef METROWERKSPOWERPC
- extern DestructorChain* __local_destructor_chain;
- extern "C" void __destroy_local_objects_to(DestructorChain *lastregmem);
- #endif
-
- //
- // Globals for the exception handler
- //
- TException* gExceptionStack;
- SInt32 gExceptionMessage;
- SInt32 gExceptionError;
-
- #pragma segment Resident
- //----------------------------------------------------------------------------------------
- // TException::TException:
- //----------------------------------------------------------------------------------------
- TException::TException()
- {
- fPrevious = gExceptionStack;
- gExceptionStack = this;
- fFired = false;
-
- //
- // Since we're just constructing the TException, we don't have any exception actions
- //
- fExceptionAction = nil;
-
- //
- // Save the A5 world
- //
- #ifdef SIXTYEIGHTK
- fA5 = GetA5();
- #endif
-
- #ifdef METROWERKSPOWERPC
- //
- // Save the current local destructor chain so when we fail we can destroy all objects
- // allocated on the stack past this point.
- //
- fLocalDestructorChain = __local_destructor_chain;
- #endif
- }
-
-
- //----------------------------------------------------------------------------------------
- // TException::~TException:
- //
- // If we caught an exception we will already be off the stack
- //----------------------------------------------------------------------------------------
- TException::~TException()
- {
- if (fFired == false)
- {
- if (gExceptionStack != this)
- {
- ASSERTPRINT(false, ("PopExceptionHandler - Stack nesting error"));
- SysError(dsLoadErr);
- }
-
- gExceptionStack = fPrevious;
- }
- }
-
-
- //----------------------------------------------------------------------------------------
- // Fail:
- //----------------------------------------------------------------------------------------
- void Fail(SInt32 error, SInt32 message)
- {
- // ASSERTPRINT(!gDebugGlobals->dbgExceptionBreaking, ("Fail(%d, %d)", error, message));
-
- gExceptionError = error;
- gExceptionMessage = message;
-
- FailAgain();
- }
-
-
- //----------------------------------------------------------------------------------------
- // FailAgain:
- //----------------------------------------------------------------------------------------
- void FailAgain()
- {
- TException* exception = gExceptionStack;
-
- if (exception == nil)
- {
- ASSERTPRINT(false, ("FAIL() with no handlers!"));
- SysError(dsLoadErr);
- }
-
- exception->fFired = true;
- gExceptionStack = exception->fPrevious;
-
- #ifdef METROWERKSPOWERPC
- //
- // Destroy any objects allocated on the stack since we began this exception block.
- // We have to do this because otherwise local objects get destroyed at some undefined
- // later point and often they’ve been overwritten by subsequent stack allocations!
- //
- __destroy_local_objects_to(exception->fLocalDestructorChain);
- #else
- //
- // Most compilers (CFront and xlC, anyway) do not support destruction of local objects
- // after a longjmp. The only destructors we really care about are TLoops since that’s
- // where the TList gets unlocked. To prevent the list from being locked forever, we
- // make sure that any loops that were allocated within the current exception frame are
- // cleaned up properly.
- //
- TExceptionAction* exceptionAction = exception->RemoveExceptionAction();
- while(exceptionAction != nil)
- {
- exceptionAction->CatchException();
- exceptionAction = exception->RemoveExceptionAction();
- }
- #endif
-
- //
- // Last, restore the 68K a5
- //
- #ifdef SIXTYEIGHTK
- SetA5(exception->fA5);
- #endif
-
- longjmp(exception->fEnv, 0);
- }
-
-
- /*
- August 18, 1993, 7:06pm, Cupertino, CA.
-
- It was going to be a wild, delirious night, free of clouds and antelopes, but the sun had not yet set, and
- the air was still full of the summer California belief. But later this evening, Mike knew that all would
- be different, and those that smiled in the direction of the ocean would wonder why they dreamed the sequence
- of yesterday's lunch. Tonight, Mike knew, was the beginning of a new circular metaphor of forested valleys.
-
- But wait! How could I babble all this? Who am I to declare the meaning of today's final yawn of sky?
- Humble me greatly, before I declare to understand the world, let alone myself.
-
- As I wander through the forest of my own distainful glance toward the South, I trip and fall, landing on
- the ice cream cone of a child that had already grown. This, I declare is my fate, and I will live it and
- believe it with all my might.
-
- - an anonymous Clam Seeking Apple Engineer, wandering, ever wandering.
- (I really should not leave Mike Lockwood near my machine with files checked out -andy)
- */
-
- #endif
-